package net.sourceforge.jFuzzyLogic.test;

import net.sourceforge.jFuzzyLogic.FIS;
import net.sourceforge.jFuzzyLogic.rule.FuzzyRuleSet;

/**
 * Test parsing an FCL file
 * @author pcingola@users.sourceforge.net
 */
public class Zzz {

	/**
	 * TODO: Generilized singlgeton (see membershipFunctionsDemo.fcl)
	 * 
	 * TODO: Singletons as functions of inputs (suggested by Stefan Schmidt <sschmidt@it.uts.edu.au>)
	 *		DEFUZZIFY valve
	 *			// Instead if Singleton you specify a function like this:
	 *			TERM drainage := FUNCTION (pressure * 5) + (temp * 3) + 6; 
	 */

	public static void main(String[] args) throws Exception {
		boolean show = true;

		// Load from 'FCL' file
		String fileName = "fcl/zzz.fcl";
		FIS fis = FIS.load(fileName, show);
		if( fis == null ) { // Error while loading?
			System.err.println("Can't load file: '" + fileName + "'");
			return;
		}

		// Get rule set
		FuzzyRuleSet fuzzyRuleSet = fis.getFuzzyRuleSet();

		// Show ruleset
		if( show ) fuzzyRuleSet.chart();

		for( int i = 0; i < 5; i++ ) {
			// Set inputs
			fuzzyRuleSet.setVariable("pressure", 60 + 5 * i);
			fuzzyRuleSet.setVariable("temp", 15 + 2 * i);
			// Evaluate fuzzy rule set
			fuzzyRuleSet.evaluate();
			System.out.println("Temp: " + fuzzyRuleSet.getVariable("temp").getValue() + ", Pressure: " + fuzzyRuleSet.getVariable("pressure").getValue() + " => Valve: " + fuzzyRuleSet.getVariable("valve").getLatestDefuzzifiedValue());
			// System.out.println(fuzzyRuleSet);
		}

		// Print ruleSet
		if( show ) System.out.println(fuzzyRuleSet);
		System.out.println(fuzzyRuleSet.toStringFCL());
	}
}
